/// Setting up for Logt Analysis
clear
use "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/anes_cdf.dta"
set more off
keep VCF0004 VCF0101 VCF0102 VCF0103 VCF0104 VCF0105 VCF0106 VCF0106a VCF0107 VCF0108 VCF0109 VCF0110 VCF0111 VCF0112 VCF0113 VCF0114 VCF0127 VCF0128 VCF0128a VCF0128b VCF0130 VCF0130a VCF0131 VCF0140 VCF0140a VCF0148 VCF0148a VCF0149 VCF0152 VCF0301 VCF0303 VCF0704a VCF0704

rename VCF0004 year
rename VCF0101 age
rename VCF0102 age_group
rename VCF0103 age_cohort
rename VCF0104 gender
rename VCF0105 race_2cat
rename VCF0106 race_3cat
rename VCF0106a race_6cat
rename VCF0107 Hisp_origin_type
rename VCF0108 Hisp_origin
rename VCF0109 Ethnicity
rename VCF0110 Education_4cat
rename VCF0111 Urbanism
rename VCF0112 Census_region
rename VCF0113 Political_South
rename VCF0114 Income
rename VCF0127 Union
rename VCF0128 religion
rename VCF0128a Religion_7cat
rename VCF0128b Religion_8cat
rename VCF0131 Weekly_Church2
rename VCF0140 education_6cat
rename VCF0140a education_7cat
rename VCF0148 socialclass_8cat
rename VCF0148a socialclass_6cat
rename VCF0149 socialclass_6cat2
rename VCF0301 PID_7
rename VCF0303 PID_sum
rename VCF0704 presvote_major
rename VCF0704a presvote_2party
rename VCF0130 weekly_church

drop if presvote_2party==.

gen female = 0
replace female=1 if gender ==2
gen Latino =0 
replace Latino=1 if race_6cat==5
gen Black =0 
replace Black=1 if race_6cat==2
gen nonwhite =0
replace nonwhite = 1 if race_3cat==3 | race_3cat==2
gen Asian = 0
replace Asian = 1 if race_6cat==3
gen demvote=0
replace demvote=1 if presvote_2party == 1
gen DemID =0
replace DemID =1 if PID_sum == 1
gen IncTopThird = 0
replace IncTopThird = 1 if Income == 5 | Income ==4
gen IncBottomThird = 0
replace IncBottomThird = 1 if Income == 1 | Income ==2
gen South = 0
replace South = 1 if Census_region == 3
gen white_southerner = 0
replace white_southerner = 1 if Census_region == 3 & race_3cat==1
gen collegegrad =0 
replace collegegrad = 1 if education_6cat==6
gen unionmember=0
replace unionmember =1 if Union==1
gen Jew = 0
replace Jew =1 if religion==3
gen Catholic =0
replace Catholic =1 if religion==2 & nonwhite==0
gen urban =0
replace urban=1 if Urbanism==1
gen rural=0
replace rural=1 if Urbanism==3
gen BoomerCohort=0
replace BoomerCohort=1 if age_cohort==4
gen genX=0
replace genX=1 if age_cohort==3
gen genY=0
replace genY=1 if age_cohort==2
gen weeklychurch=0
replace weeklychurch=1 if weekly_church==1
replace weeklychurch=1 if Weekly_Church2==1 & year<1969
gen nonreligious=0
replace nonreligious=1 if religion==4
gen GreatestGen = 0 
replace GreatestGen=1 if age_cohort==6
gen Preboomers =0
replace Preboomers=1 if age_cohort==5
gen Under_35 = 0
replace Under_35 =1 if age<=35
gen Over_60 = 0
replace Over_60 = 1 if age>=65



gen d1952 =0
replace d1952=1 if year==1952
gen d1956 =0
replace d1956=1 if year==1956
gen d1960 =0
replace d1960=1 if year==1960
gen d1964 =0
replace d1964=1 if year==1964
gen d1968 =0
replace d1968=1 if year==1968
gen d1972 =0
replace d1972=1 if year==1972
gen d1976 =0
replace d1976=1 if year==1976
gen d1980 =0
replace d1980=1 if year==1980
gen d1984 =0
replace d1984=1 if year==1984
gen d1988 =0
replace d1988=1 if year==1988
gen d1992 =0
replace d1992=1 if year==1992
gen d1996 =0
replace d1996=1 if year==1996
gen d2000=0
replace d2000=1 if year==2000
gen d2004=0
replace d2004=1 if year==2004
gen d2008=0
replace d2008=1 if year==2008
gen d1950s = 0
replace d1950s=1 if year==1952 | year==1956
gen d1960s = 0
replace d1960s=1 if year==1960 | year==1964 | year==1968
gen d1970s = 0
replace d1970s=1 if year==1972 | year==1976
gen d1980s = 0
replace d1980s=1 if year==1980 | year==1984 | year==1988
gen d1990s = 0
replace d1990s=1 if year==1992 | year==1996
gen d2000s = 0
replace d2000s=1 if year==2000 | year==2004 | year==2008
gen decade =0 
replace decade = 1 if d1960s==1
replace decade = 2 if d1970s==1
replace decade = 3 if d1980s==1
replace decade = 4 if d1990s==1
replace decade = 5 if d2000s==1

logit  demvote  Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural GreatestGen BoomerCohort Preboomers genX genY Under_35 Over_60 d1956 if decade==0
outreg2 using bydecade, replace drop(GreatestGen BoomerCohort Preboomers genX genY d1956) auto(2)
margins, dydx(Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural Under_35 Over_60)
marginsplot,  plotopts(lcolor(none)) horiz title(1950s) ytitle(Group) xtitle(Effect on Probability of Dem Vote) xline(0) xlabel(-.2(.1).4) ylabel(1 "Black" 2 "Latino" 3 "Asian" 4 "Female" 5 "Inc. Top 1/3" 6 "Inc. Bottom 1/3" 7 "White Southerner" 8 "College Graduate" 9 "Union Member" 10 "Jew" 11 "Catholic" 12 "Church Attendee" 13 "Non Religious" 14 "Urban" 15 "Rural" 16 "Under 35" 17 "Over 60")
graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade0.gph", replace

logit  demvote  Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural GreatestGen BoomerCohort Preboomers genX genY Under_35 Over_60 d1964 d1968 if decade==1
outreg2 using bydecade, append drop(GreatestGen BoomerCohort Preboomers genX genY d1964 d1968) auto(2)
margins, dydx(Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural Under_35 Over_60 )
marginsplot,  plotopts(lcolor(none)) horiz title(1960s) ytitle(Group) xtitle(Effect on Probability of Dem Vote) xline(0) xlabel(-.2(.1).4) ylabel(1 "Black" 2 "Latino" 3 "Asian" 4 "Female" 5 "Inc. Top 1/3" 6 "Inc. Bottom 1/3" 7 "White Southerner" 8 "College Graduate" 9 "Union Member" 10 "Jew" 11 "Catholic" 12 "Church Attendee" 13 "Non Religious" 14 "Urban" 15 "Rural" 16 "Under 35" 17 "Over 60" )
graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade1.gph", replace

logit  demvote  Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural GreatestGen BoomerCohort Preboomers genX genY Under_35 Over_60 d1976 if decade==2
outreg2 using bydecade, append drop(GreatestGen BoomerCohort Preboomers genX genY d1976) auto(2)
margins, dydx(Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural Under_35 Over_60)
marginsplot,  plotopts(lcolor(none)) horiz title(1970s) ytitle(Group) xtitle(Effect on Probability of Dem Vote) xline(0) xlabel(-.2(.1).4)  ylabel(1 "Black" 2 "Latino" 3 "Asian" 4 "Female" 5 "Inc. Top 1/3" 6 "Inc. Bottom 1/3" 7 "White Southerner" 8 "College Graduate" 9 "Union Member" 10 "Jew" 11 "Catholic" 12 "Church Attendee" 13 "Non Religious" 14 "Urban" 15 "Rural" 16 "Under 35" 17 "Over 60" )
graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade2.gph", replace  

logit  demvote  Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural GreatestGen BoomerCohort Preboomers genX genY Under_35 Over_60 d1984 d1988 if decade==3
outreg2 using bydecade, append drop(GreatestGen BoomerCohort Preboomers genX genY d1984 d1988) auto(2)
margins, dydx(Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious nonreligious urban rural Under_35 Over_60)
marginsplot,   plotopts(lcolor(none)) horiz title(1980s) ytitle(Group) xtitle(Effect on Probability of Dem Vote) xline(0) xlabel(-.2(.1).4)  ylabel(1 "Black" 2 "Latino" 3 "Asian" 4 "Female" 5 "Inc. Top 1/3" 6 "Inc. Bottom 1/3" 7 "White Southerner" 8 "College Graduate" 9 "Union Member" 10 "Jew" 11 "Catholic" 12 "Church Attendee" 13 "Non Religious" 14 "Urban" 15 "Rural" 16 "Under 35" 17 "Over 60")
graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade3.gph", replace 

logit  demvote  Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious nonreligious urban rural GreatestGen BoomerCohort Preboomers genX genY Under_35 Over_60 d1996 if decade==4
outreg2 using bydecade, append drop(GreatestGen BoomerCohort Preboomers genX genY d1996) auto(2)
margins, dydx(Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural Under_35 Over_60)
marginsplot,  plotopts(lcolor(none)) horiz title(1990s) ytitle(Group) xtitle(Effect on Probability of Dem Vote) xline(0) xlabel(-.2(.1).4)  ylabel(1 "Black" 2 "Latino" 3 "Asian" 4 "Female" 5 "Inc. Top 1/3" 6 "Inc. Bottom 1/3" 7 "White Southerner" 8 "College Graduate" 9 "Union Member" 10 "Jew" 11 "Catholic" 12 "Church Attendee" 13 "Non Religious" 14 "Urban" 15 "Rural" 16 "Under 35" 17 "Over 60" )
graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade4.gph", replace 

logit  demvote  Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural GreatestGen BoomerCohort Preboomers genX genY Under_35 Over_60  d2004 d2008 if decade==5
outreg2 using bydecade, append drop(GreatestGen BoomerCohort Preboomers genX genY d2004 d2008) auto(2)
margins, dydx(Black Latino Asian female IncTopThird IncBottomThird white_southerner collegegrad unionmember Jew Catholic weeklychurch nonreligious urban rural Under_35 Over_60)
marginsplot,  plotopts(lcolor(none)) horiz title(2000s) ytitle(Group) xtitle(Effect on Probability of Dem Vote) xline(0) xlabel(-.2(.1).4)   ylabel(1 "Black" 2 "Latino" 3 "Asian" 4 "Female" 5 "Inc. Top 1/3" 6 "Inc. Bottom 1/3" 7 "White Southerner" 8 "College Graduate" 9 "Union Member" 10 "Jew" 11 "Catholic" 12 "Church Attendee" 13 "Non Religious" 14 "Urban" 15 "Rural" 16 "Under 35" 17 "Over 60")
graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade5.gph", replace 

graph combine "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade0.gph" ///
"/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade1.gph" ///
"/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade2.gph" ///
"/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade3.gph" ///
"/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade4.gph" ///
"/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/Decade5.gph",  xsize(9) ysize(5) title(The Effect of Group Membership on Democratic Vote Choice in Presidential Elections)graphregion(lcolor(black))




graph save Graph "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/combined.gph", replace

